{% extends 'myadmin/base/content_base.html' %}
{% load static %}

{% block page_header %}
    系统设置
{% endblock %}
{% block page_option %}
    权限分组
{% endblock %}

{% block content %}
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">分组详情</h3>
        </div>
        <!-- /.box-header -->
        <!-- form start -->
        <div class="box-body">
            <div class="row">
                <div class="col-md-3"></div>
                <div class="col-md-6">
                    <form class="form-horizontal">
                        {% csrf_token %}

                        {% for field in form %}
                            {% if field.name == 'permissions' %}
                                <div class="form-group {% if field.errors %}has-error{% endif %}">

                                    <label for="{{ field.id_for_label }}"
                                           class="col-sm-2 control-label">{{ field.label }}</label>

                                    <div class="col-sm-10">
                                        {% for error in field.errors %}
                                            <label class="control-label"
                                                   for="{{ field.id_for_label }}">{{ error }}</label>
                                        {% endfor %}
                                        {% for menu in menus %}
                                            <div class="row" style="margin: 0">
                                                <div class="checkbox">
                                                    <label for="menu_{{ menu.permission.id }}">
                                                        <input {% if menu.permission in permissions %}checked{% endif %} type="checkbox" name="permissions" id="menu_{{ menu.permission.id }}"
                                                               value="{{ menu.permission.id }}">{{ menu.name }}
                                                    </label>
                                                </div>
                                                {% for child in menu.children.all %}
                                                    <div class="checkbox col-sm-offset-1">
                                                        <label for="menu_{{ child.permission.id }}">
                                                            <input type="checkbox" {% if child.permission in permissions %}checked{% endif %} name="permissions" id="menu_{{ child.permission.id }}"
                                                                   value="{{ child.permission.id }}">{{ child.name }}
                                                        </label>
                                                    </div>
                                                {% endfor %}

                                            </div>
                                        {% endfor %}

                                    </div>
                                </div>
                            {% else %}
                                <div class="form-group {% if field.errors %}has-error{% endif %}">

                                    <label for="{{ field.id_for_label }}"
                                           class="col-sm-2 control-label">{{ field.label }}</label>

                                    <div class="col-sm-10">
                                        {% for error in field.errors %}
                                            <label class="control-label"
                                                   for="{{ field.id_for_label }}">{{ error }}</label>
                                        {% endfor %}
                                        {{field}}
                                    </div>
                                </div>
                            {% endif %}
                        {% endfor %}


                    </form>
                </div>
                <div class="col-md-3"></div>
            </div>
        </div>
        <div class="box-footer">

            <button type="button" class="btn btn-default back">返回</button>
            <button type="button"
                                        {% if form.instance.id %}
                    data-url="{% url 'myadmin:group_update' form.instance.id %}"
                    data-type="PUT"
                    {% else %}
                    data-url="{% url 'myadmin:group_add' %}"
                    data-type="POST"
                    {% endif %}
                    class="btn btn-primary pull-right save">保存
            </button>



        </div>
    </div>
{% endblock %}
{% block script %}
    <script src="{% static 'js/myadmin/group/group_detail.js' %}"></script>
{% endblock %}
